import 'package:flutter/material.dart';

class MyButtonGradient extends StatelessWidget {
  final VoidCallback? onTap;          // 点击事件回调
  final double? width;                // 宽度（可选）
  final double? height;               // 高度（可选）
  final Widget child;                 // 子组件内容（如 Text、Row 等）
  final BorderRadius? borderRadius;  // 可选圆角
  final List<Color>? colors;         // 可选渐变色列表

  const MyButtonGradient({
    Key? key,
    required this.child,
    this.onTap,
    this.width,
    this.height = 40,
    this.borderRadius,
    this.colors,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        alignment: Alignment.center,
        height: height,
        width: width ?? MediaQuery.of(context).size.width - 30,
        decoration: BoxDecoration(
          borderRadius: borderRadius ?? BorderRadius.circular(20),
          gradient: LinearGradient(
            colors: colors ?? [Color(0xFFF89596), Color(0xFFFF4142)], // 默认渐变
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
          ),
        ),
        child: child,
      ),
    );
  }
}
